package com.dot.dominion.view;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.dot.dominion.R;
import com.dot.dominion.domain.Card;

public class HandAdapter extends ArrayAdapter {
	private Activity mContext;
	private Card[] cardList;
	
	public HandAdapter(Activity context, Card[] list) {
		super( context, R.layout.handview_item, list);
		
		mContext = context;
		cardList = list;
	}
	
	public View getView(int position, View convertView, ViewGroup parent) {
		View item = convertView;
		HandWrapper wrapper = null;
		
		if( convertView == null ) {
			LayoutInflater inflater = (LayoutInflater) mContext.
							getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			
			item = inflater.inflate(R.layout.handview_item, null);
			wrapper = new HandWrapper(item);
			item.setTag(wrapper);
		}
		else
			wrapper = (HandWrapper) item.getTag();
		
		wrapper.getText().setText(cardList[position].getName());
		
		if( cardList[position].isVictoryCard()) {
			item.setBackgroundResource( R.color.handview_victory );
		}
		else {
			item.setBackgroundResource( R.color.handview_treasure );
		}
		
		return item;
	}
}
